<template>
  <view class="wrap">
    <!-- <view class="search">
      <u-search v-model="keywords" @custom="search" @search="search" @clear="clear"></u-search>
	  <js-select
	  	v-model="query.taskLeader"
	  	:items="userSelectList"
	  	placeholder="请选择牵头领导"
	  	
	  	@confirm="getLeaderOrg(arguments)"
	  	:label-value="query.taskLeaderName"
	  	@label-input="query.taskLeader = $event"
	  ></js-select>
    </view> -->
	<u-form class="form" :model="query" ref="uForm" label-position="left">
		<u-form-item label="关键字" label-width="180"><u-input placeholder="请输入任务标题或内容查询" v-model="query.taskTitle" type="text" maxlength="200"></u-input></u-form-item>
		
		<u-form-item label="牵头领导" label-width="180">
			<js-select
				v-model="query.taskLeader"
				:items="userSelectList"
				placeholder="请选择牵头领导"
				
				@confirm="getLeaderOrg(arguments)"
				:label-value="query.taskLeaderName"
				@label-input="query.taskLeader = $event"
			></js-select>
		</u-form-item>
	
	</u-form>
	<view class="uni-flex" style="-webkit-justify-content: flex-end;justify-content: flex-end;margin-bottom: 10rpx;">
		<u-button type="primary" style="margin-top: 5rpx; width: 30%; margin-bottom: 4rpx" @click="doQuery" :plain="true" :hairline="true" text="查询">查询</u-button>
		<u-button type="primary" style="margin-top: 5rpx; width: 30%; margin-bottom: 4rpx" @click="resetAll" :plain="true" :hairline="true" text="重置">重置</u-button>
	</view>

    <scroll-view class="scroll-list" scroll-y="true" @scrolltolower="loadMore">
      <u-cell-group class="list" :border="false">
        <u-swipe-action
          v-for="(item, index) in list"
          :key="item.id"
          :index="index"
        >
          <u-cell-item
            :arrow="true"
            @click="navTo('/pages/task/ldIndex/ldIndexDetails?id=' + item.id+'&taskLeader='+query.taskLeader)"
            style="border-bottom: 1px solid #ededed"
          >
            <text slot="title" class="u-line-1 content-span ss">{{ item.taskTitle }}</text>
            <view slot="label" style="padding-bottom:20rpx">任务类型：{{ item.taskTypeName }}</view>
            <text slot="label">任务状态：{{ item.taskStatusStr || '无' }} </text>
            <text slot="label">
              <u-button
                type="primary"
                style="margin-top: 25rpx; width: 250rpx; margin-bottom: 4rpx;float:right"
                @click="showModal(item)"
                :plain="true"
                :hairline="true"
                text="批示"
                >批示</u-button
              >
            </text>
          </u-cell-item>
        </u-swipe-action>
      </u-cell-group>

      <view class="loadmore" @click="loadMore">
        <u-loadmore :status="loadStatus"></u-loadmore>
      </view>
    </scroll-view>
    
    <u-modal
      v-model="show"
      title="领导批示"
      ref="uModal"
      :show-cancel-button="true"
      confirmText="确定"
      cancelText="取消"
      @cancel="cancel"
      @confirm="confirm"
    >
      <view class="u-update-content" style="margin-top: 20rpx">
        <textarea
          type="text"
          style="
            width: 90%;
            margin: auto;
            height: 200rpx;
            border: 1px solid #ccc;
            font-size: 14px;
          "
          v-model="content"
          placeholder-class="line"
          maxlength="100"
          placeholder="文字限制在100字以内"
        />
        
      </view>
    </u-modal>
  </view>
</template>
<script>
/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
export default {
  data() {
    return {
      keywords: "",
      query: {
        pageNo: 1,
        pageSize: 20,
        taskTitle:'',
        taskLeader:'',
        taskLeaderName:'',
      },
      list: [],
      userSelectList: [],
      count: 0,
      loadStatus: "loadmore",
      options: [{ text: "删除", style: { background: "#dd524d" } }],
      show: false,
      content: "",
      parsm:{
        actionId:'',
        explainCode:'',
        explainContent:''
      },
      explainContent:''
    };
  },
  onLoad() {
	  this.query.taskLeader=this.vuex_user.userCode
    this.loadList();
	this.$u.api.taskInfo.getLeader().then(res => {
		res.data.map(item => {
			this.userSelectList.push({
				name: item.refName,
				value: item.refCode
			});
		});
	});
   
  },
  onShow() {
    if (uni.getStorageSync("refreshList") === true) {
      uni.removeStorageSync("refreshList");
      this.search("");
    }
  },
  methods: {
	  doQuery() {
	  	this.list = [];
	  	this.loadList();
	  },
	  resetAll() {
	  	
		this.query.taskLeader=this.vuex_user.userCode
	  	this.query.taskTitle = '';
	  	this.query.taskLeaderName = '';
	  	this.list = [];
	  	this.loadList();
	  },
    loadMore() {
      this.loadStatus = "loading";
      setTimeout(() => {
        this.query.pageNo += 1;
        this.loadList();
      }, 100);
    },
	getLeaderOrg(value) {
		if(value.length > 1){
		this.query.taskLeader = value[0];
		this.query.taskLeaderName = value[1];	
		}else{
			this.query.taskLeader = value[0].label;
			this.query.taskLeaderName = value[0].value;
		}
		
	},
    loadList() {
		this.query.taskYear = new Date().getFullYear();
      
      this.$u.api.homePage.queryWorkList(this.query).then((res) => {
        for (var i = 0; i < res.list.length; i++) {
					if(res.list[i].taskStatus==2){
						res.list[i].taskStatusStr="已发布"
					}
					if(res.list[i].taskStatus==3){
						res.list[i].taskStatusStr="任务部署审核通过"
					}
					if(res.list[i].taskStatus==4){
						res.list[i].taskStatusStr="任务部署审核驳回"
					}
					if(res.list[i].taskStatus==5){
						res.list[i].taskStatusStr="秘书长审核通过"
					}
					if(res.list[i].taskStatus==6){
						res.list[i].taskStatusStr="秘书长审核驳回"
					}
					if(res.list[i].taskStatus==7){
						res.list[i].taskStatusStr="已确认"
					}
					if(res.list[i].taskStatus==8){
						res.list[i].taskStatusStr="进行中"
					}
					if(res.list[i].taskStatus==9){
						res.list[i].taskStatusStr="已结束"
					}
					
				}
        if (!res.list || res.list.length == 0) {
          this.loadStatus = "nomore";
          return;
        }
        this.list = res.list;
        this.count = res.count;
        this.query.pageNo = res.pageNo;
        this.query.pageSize = res.pageSize;
        this.loadStatus = "loadmore";
      });
    },

    search(value) {
      this.list = [];
      this.query.pageNo = 0;
      this.query.taskTitle = value;
      this.loadList();
    },
    clear(){
		  this.keywords=''
      this.list = [];
      this.query.pageNo = 0;
      this.loadList();
	  },
    navTo(url) {
      uni.navigateTo({
        url: url,
      });
    },
    showModal(value) {
      this.show = true;
      this.parsm.actionId=value.id;
      this.explainContent ='';
    },
    confirm() {
      // if (this.content.length > 0) {
      //   this.show = false;
      // } else {
      //   // uni.showToast({
      //   //   title: "请输入批示内容",
      //   //   icon: "none",
      //   // });
      //   // this.show = true;
      // }
      this.parsm.explainCode=this.vuex_user.userCode
      this.parsm.explainContent=this.content;
      this.$u.api.homePage.getSave(this.parsm).then(res => {
         this.content="";
				this.loadList();
        
			});
    },
    cancel() {
      this.show = false;
      this.content="";
    },
  },
};
</script>
<style lang="scss">
page {
  background-color: #f8f8f8;
}
.btn-plus {
  position: absolute;
  bottom: 50rpx;
  right: 50rpx;
  z-index: 1;
  opacity: 0.6;
}
.btn-plus:hover {
  opacity: 1;
}
.uni-flex {
	display: flex;
	flex-direction: row;
}
</style>
